package com.momo.service.authority;

import com.google.common.collect.Multimap;
import com.momo.common.res.authority.AclDto;
import com.momo.common.res.authority.AclModuleLevelDto;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * Created by MOMO on 2019/3/26.
 * 动态权限模块组件
 */
@Service
public class DynamicAclModule {
    public void ownAclModule(Multimap<Long, AclModuleLevelDto> multimap, List<AclDto> aclDtoList, Set<AclModuleLevelDto> set) {

        int size = aclDtoList.size();
        for (int i = 0; i < size; i++) {
            AclDto aclDto = aclDtoList.get(i);
            ownAclModuleToSeparation(multimap, set, aclDto.getSysAclModuleId());
        }
    }

    private void ownAclModuleToSeparation(Multimap<Long, AclModuleLevelDto> multimap, Set<AclModuleLevelDto> set, Long moduleId) {
        List<AclModuleLevelDto> aclModuleDOS = (List<AclModuleLevelDto>) multimap.get(moduleId);
        if (!CollectionUtils.isEmpty(aclModuleDOS)) {
            AclModuleLevelDto aclModuleDO = aclModuleDOS.get(0);
            set.add(aclModuleDO);
            ownAclModuleToSeparation(multimap, set, aclModuleDO.getSysAclModuleParentId());
        }
    }
}
